package com.hd.crdao.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.hd.crdao.R;
import com.hd.crdao.activity.CarDetailsActivity;
import com.hd.crdao.bean.AllInfoBean;
import com.hd.crdao.config.Constants;
import com.hd.crdao.utils.UIUtils;
import com.hd.crdao.wrapper.GlideImageUtils;

import java.util.List;

/**
 * @author Programming
 * @date 2017/9/19 0019
 */

public class HomeRVAdapter extends RecyclerView.Adapter<HomeRVAdapter.ViewHolder> {
    private List<AllInfoBean.CarInfoListBean> mDataList;
    private Context mContext;

    public HomeRVAdapter(List<AllInfoBean.CarInfoListBean> dataList, Context context) {
        mDataList = dataList;
        mContext = context;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = View.inflate(UIUtils.getContext(), R.layout.item_home, null);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(final ViewHolder holder,  int position) {
        AllInfoBean.CarInfoListBean carInfoListBean = mDataList.get(position);
        //设置数据
        holder.mCarDesc.setText(carInfoListBean.getVehConfig().getVcTypenme());
        String url = Constants.IMAGEURL + carInfoListBean.getCoverPath();
       // Glide.with(UIUtils.getContext()).load(url).placeholder(R.drawable.logo_moren_2x).into(holder.mCarImage);
        GlideImageUtils.loadImage(url,holder.mCarImage);
        holder.mCarLocation.setText(carInfoListBean.getCiPlatearea());
        holder.mCarPrice.setText(String.format("%s万", carInfoListBean.getCiExpectprice()));
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(UIUtils.getContext(), CarDetailsActivity.class);
                intent.putExtra("carid", mDataList.get(holder.getAdapterPosition()-2).getId());
                mContext.startActivity(intent);
            }
        });
    }


    @Override
    public int getItemCount() {
        return mDataList != null ? mDataList.size() : 0;
    }


    class ViewHolder extends RecyclerView.ViewHolder {
        ImageView mCarImage;
        TextView mCarDesc;
        TextView mCarLocation;
        TextView mCarPrice;

        public ViewHolder(View itemView) {
            super(itemView);
            mCarImage = (ImageView) itemView.findViewById(R.id.car_image);
            mCarDesc = (TextView) itemView.findViewById(R.id.car_desc);
            mCarLocation = (TextView) itemView.findViewById(R.id.car_location);
            mCarPrice = (TextView) itemView.findViewById(R.id.car_price);
        }
        //  TextView mModelDesc;
    }



}
